
package de.dtools.n2g.start;

/**
 *	@project:	note2go
 *	@author:	D.Toepel
 *	@version:	2009-08-04
 *	@note:		---
 *	
 *	Copyright (C) 2009  D.Toepel <de.dtools> {at} <gmail> {dot} <com>
 *	
 *	This program is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *	
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *	
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *	
 */

import java.awt.event.ActionEvent;

import javax.swing.*;

import de.dtools.n2g.core.Note2Go;
import de.dtools.n2g.res.Resource;
import de.dtools.n2g.sql.Database;


public class N2GStartup {
	
	
	static N2GClassLoader cl;

	
	public static void main(String[] args) {
		
		// load Classes
		cl = new N2GClassLoader(args);
		Resource res = new Resource();
		String dbURL = res.getCurrPath()+
			System.getProperty("file.separator") + "data" +
			System.getProperty("file.separator") + 	"notes";
		
		final Database iDB = new Database();
		iDB.setDbData(new Object[]{dbURL,null,null});

		// show login
		N2GLogin.setDatabase(iDB);
		final N2GLogin login = new N2GLogin();
		login.addN2GLoginEventListener(new N2GLoginEvents() {
			
			@Override
			public void actionPerformed(ActionEvent e) {}
			
			@Override
			public void loginAction(ActionEvent evt) {
				if(evt.getActionCommand().matches("logged in")){
					
					// start mainframe
					SwingUtilities.invokeLater(new Runnable() {
						
						@Override
						public void run() {
							Note2Go.setDatabase(iDB);
							Note2Go inst = new Note2Go();
							inst.setLocationRelativeTo(null);				
							inst.setIconImage(
									new ImageIcon(
											getClass().getClassLoader().getResource(
													"de/dtools/n2g/res/png/icon.png")).getImage());
							inst.setVisible(true);
							inst.toFront();
						}
					});
				}
				login.dispose();
			}
		});
		login.setLocationRelativeTo(null);	
		login.setUndecorated(true);
		login.setVisible(true);
		login.setAlwaysOnTop(true);
	}
	
	
}
